import { _decorator, Collider2D, Component, Contact2DType, director, IPhysics2DContact, Node, Script, Tween, tween, UITransform, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('item')
export class item extends Component {

    @property(Node)
    parentsNode: Node = null;

    public posY: number = 0;

    start() {
    }

    protected onLoad(): void {
        if (this.node.position.y > this.posY) {
            this.moveToBottom();
        } else {
            this.moveInertia();
        }
    }
    // 移动到底部
    moveToBottom() {
        tween(this.node)
        .to(0.3 * (this.node.position.y - this.posY) / this.node.getComponent(UITransform).height, { position: new Vec3(this.node.position.x, this.posY, this.node.position.z)}, {
            onUpdate: (target: Vec3) => {
                // this.node.position = target;
            }
        })
        .call(() => {
            this.moveInertia();
        })
        .start();
    }

    // 到达目的地动画
    moveInertia() {
        const position =  this.node.position;
        tween(this.node)
        .to(0.2, { position: new Vec3(position.x, position.y + 20, position.z) })
        .to(0.3, { position: new Vec3(position.x, position.y, position.z) })
        .call(() => {
        })
        .start();
    }

    update(deltaTime: number) {
        
    }
}


